import React from 'react';
import { fetchTasklist } from '../Employee/service';

// 任务列表
const useTaskList = query => {
    const [resData, setResData] = React.useState([]);
    const [loading, setLoading] = React.useState(true);
    const [total, setTotal] = React.useState(0);

    const fetchData = async () => {
        setLoading(true);
        const { data: rowData = {}, code } = (await fetchTasklist(query)) || {};
        const { total: rowTotal = 0, rows = [] } = rowData;

        if (code === 10000) {
            setResData(rows);
            setTotal(rowTotal);
        }
        setLoading(false);
    };

    React.useEffect(() => {
        fetchData();
    }, [query]);

    return [loading, resData, total];
};

export default useTaskList;
